package com.heima.article.kafkaListener;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.heima.article.mapper.ApArticleConfigMapper;
import com.heima.model.article.pojos.ApArticleConfig;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class Listener {
    @Resource
    private ApArticleConfigMapper apArticleConfigMapper;
    @KafkaListener(topics = "enable")
    public void enable(String msg){
        String[] split = msg.split("&");
        ApArticleConfig apArticleConfig = new ApArticleConfig(Long.parseLong(split[0]));
        apArticleConfig.setIsDown(split[1].equals("0"));
        LambdaUpdateWrapper<ApArticleConfig> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(ApArticleConfig::getArticleId,split[0]);
        apArticleConfigMapper.update(apArticleConfig,wrapper);
    }
}
